package com.scuec.groupfive.controller;

import com.scuec.groupfive.entity.QuestionInfo;
import com.scuec.groupfive.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.scuec.groupfive.entity.Questions;
import org.springframework.http.ResponseEntity;
import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api/questions")
public class QuestionController {
    @Resource
    private QuestionService questionService;

    @PutMapping("/update")
    public int updateQuestionInfo(@RequestBody QuestionInfo questionInfo) {
        return questionService.updateQuestionInfo(questionInfo);
    }

    @GetMapping("/{id}")
    public ResponseEntity<Questions> getQuestionById(@PathVariable Long id) {
        Questions question = questionService.getQuestionById(id);
        return ResponseEntity.ok(question);
    }

    @GetMapping("/all")
    public ResponseEntity<List<Questions>> getAllQuestions() {
        List<Questions> questions = questionService.getAllQuestions();
        return ResponseEntity.ok(questions);
    }
}